/**
 * Project: drink-maker-proj
 * Package: com.made2ordersoftware.drinkmaker.domain
 * File: IngredientEntity.java
 * Created: May 10, 2014
 */
/**
 * Copyright (c) 2010 Made 2 Order Software, LLC
 *
 * All rights reserved. No part of this software may be reproduced, stored in a retrieval system, or
 * transmitted in any form or by any means, without the prior written permission of Made 2 Order Software.
 *
 * You may not distribute the URL or redistribute the files to third parties. You may transfer the files onto
 * a single storage device so long as you can prove ownership of the software. You may not reverse engineer,
 * decompile, or disassemble the software or media files. You may not modify or translate the software or
 * media, or distribute copies of the software or media without the written consent of Made 2 Order Software,
 * LLC.
 */
package com.made2ordersoftware.drinkmaker.domain;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author David
 * @version 1.0.0
 */
@Entity
@Table(name = "ingredient")
@XmlRootElement
@NamedQueries({@NamedQuery(name = "IngredientEntity.findAll", query = "SELECT i FROM IngredientEntity i"),
    @NamedQuery(name = "IngredientEntity.findById", query
            = "SELECT i FROM IngredientEntity i WHERE i.id = :id"),
    @NamedQuery(name = "IngredientEntity.findByName", query
            = "SELECT i FROM IngredientEntity i WHERE i.name = :name")})
public class IngredientEntity implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    private Long id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    private String name;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "ingredient")
    private Collection<DrinkIngredientEntity> drinkIngredients;

    private static final Logger LOG = LoggerFactory.getLogger(IngredientEntity.class);

    public IngredientEntity() {
    }

    public IngredientEntity(String name) {
        this.name = name;
    }

    // <editor-fold defaultstate="collapsed" desc="getters-setters">
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    public Collection<DrinkIngredientEntity> getDrinkIngredients() {
        return Collections.unmodifiableCollection(drinkIngredients);
    }

    public void setDrinkIngredients(
            Collection<DrinkIngredientEntity> drinkIngredients) {
        this.drinkIngredients = drinkIngredients;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="hash-equal-tostring">
    @Override
    public int hashCode() {
        int hash = 17;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof IngredientEntity)) {
            return false;
        }
        IngredientEntity other = (IngredientEntity) object;
        return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
    }

    @Override
    public String toString() {
        return "com.made2ordersoftware.drinkmaker.domain.IngredientEntity[ id=" + id + " ]";
    }
    // </editor-fold>

}
